#ifndef SERVERSOCKET_H
#define SERVERSOCKET_H

#include "server-socket_global.h"
#include <QThread>
#include <uv.h>
#include "baseproto.h"
#include "cnsComponent.h"
#include "queue.h"

struct ServerClientSocketProc;
TAILQ_HEAD(client_list, ServerClientSocketProc);

class SERVERSOCKET_EXPORT ServerSocketProc : public CnsComponent
{
    Q_OBJECT
private:
    BaseProto       _proto;
    uv_loop_t*      _loop;

    uv_tcp_t        _socket;
    uv_timer_t      _watchdog;

    struct client_list _clients;

    uv_async_t      _async;

public:
    inline uv_async_t* getAsync()
    {
        return &_async;
    }
    inline uv_loop_t* getLoop()
    {
        return _loop;
    }
    inline void setLoop(uv_loop_t* loop)
    {
        _loop = loop;
    }
    inline BaseProto &getBaseProto()
    {
        return _proto;
    }
    inline QString getIp() {
        return property_ts("ip").toString();
    }
    inline int getPort(){
        return property_ts("port").toInt();
    }
    inline uv_tcp_t& getSocket() {
        return _socket;
    }
    struct client_list& getClientList(){
        return _clients;
    }
    inline uv_timer_t &getWatchDog()
    {
        return _watchdog;
    }
    Q_INVOKABLE ServerSocketProc(){}
};

CNS_COM_DECL_METATYPE(ServerSocketProc)

#endif // SERVERSOCKET_H
